﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
 
 
using System.Data.Objects.DataClasses;
using System.Data.Objects;
using System.Data.Metadata.Edm;
using System.Data;
using MShop.Core.DataAccess;
using MShop.Core.Service.Search;

namespace MShop.Core.Service.Context
{
    public abstract class AbstractContentItemServiceDecorator<T> : IContentItemService<T> where T : class,IEntityWithKey, ISearchableContent
    {

        private readonly IObjectContextProvider Provider;
        public AbstractContentItemServiceDecorator(IObjectContextProvider provider)
        {
            Provider = provider;
           
             
        }

        #region IContentItemService<T> Members

        public virtual void SaveObject(T obj)
        {

            Provider.ObjectContext.CreateObjectSet<T>().AddObject(obj);

             
        }

        public virtual void UpdateObject(T obj)
        {
            
        }

        public virtual void DeleteObject(T obj)
        {
            Provider.ObjectContext.DeleteObject(obj);
            
        }

        #endregion

        #region IContentItemService<T> Members


        public void SaveChanges()
        {
            Provider.ObjectContext.SaveChanges();
        }

        #endregion
    }
}
